September 1995

Creating additional swap space for Solaris 2.x

How much swap space do you have installed? For Solaris 2.x systems, the amount of swap space you have should equal the difference between your RAM and 64 MB. For example, if you have 16 MB of RAM on your system, you should also have 48 MB of swap space. This formula can be used for many situations, but when you install new software that requires more swap space than you've installed, what can you do? With a few simple commands, you can create additional swap space for your Solaris system. In this article, we'll take a look at swap space and show you how to create more when needed.

Defining swap space

Swap space is disk space used as virtual memory. When a Solaris system runs a process, it loads it into your active RAM memory. As the processes increase, RAM can fill up completely. When this happens, inactive processes are then swapped out of RAM to virtual memory created on your disk to free up RAM memory for active processes.

This swapping is done without user intervention, and the disk space used for swapping doesn't come from the normal file system. The disk area used for swap space is in the partition used by the Solaris system but is a logically separate disk area. By default, the Solaris installation procedure creates a swap file system called /swap. To view the swap space available on your system, use the command

#swap -s

and you'll see output similar to this:

total: 15936k bytes allocated + 6576k reserved = 22512k used, 63124k available

The desirable amount of swap space depends on the amount of RAM you've installed and how heavily you use the system. If you have more RAM, the system will swap less. The more you use the system, the more active processes will load into RAM and swapping will increase. Some applications require a certain amount of swap space regardless of system usage. When you install these applications, you may find it necessary to increase the size of your swap space.

Adding swap space on Solaris 2.x

To create additional swap space after your Solaris 2.x system installs, you'll need to follow a few steps. First, you create a swap file using the mkfile command. You determine the size of the swap file in kilobytes, blocks, or megabytes by using the suffixes

mkfile 1k = 1 kilobyte

mkfile 1b = 1 block (512 bytes)

mkfile 1m = 1 megabyte

You can create the swap file on a locally mounted or NFS-mounted file system.

To create the file with mkfile, log in as the superuser root and enter the command

#mkfile 10m /export/SWAP

This command creates the 10 MB file /export/SWAP. Now you can assign the file swap space using the swap -a command

#swap -a /export/SWAP

The additional swap space is now available for the system. To check your work, you can list the available swap space with the swap -l command

#swap -l

swapfile dev swaplo blocks free

/dev/dsk/c0d0s1 102,1 8 132040 132040

/export/SWAP - 8 20472 20472

However, when you add the swap space, the change isn't permanent. If you reboot, the file /export/SWAP remains on your file system, but you'll need to reissue the swap -a command to make the file available as swap space. To make the swap space permanently available, you'll need to edit the /etc/vfstab file.

The /etc/vfstab file contains information about your file system in a table format. In order for your added swap space to load each time your system boots, add the line highlighted in Figure A to your /etc/vfstab file. This makes the /export/SWAP file available as swap space each time the system boots.

If you create swap space temporarily and then decide to remove the swap space, use the command

#swap -d /export/SWAP

to remove the file /export/SWAP from your swap space. Once the swap file becomes inactive, it's removed from your swap list. However, the file you created for swap space still exists until you delete it with the rm command.

Conclusion

Having enough swap space on your system can help increase your system's performance. In this article, we've discussed how to add swap space to your Solaris 2.x system. We've also shown you how to make the swap space available each time you reboot the system by adding the swap file to your /etc/vfstab file.


[Return to Index for Inside Solaris - September Issue]

Copyright (c) 1995 The Cobb Group, a division of Ziff-Davis Publishing Company. All rights reserved.

Reproduction in whole or in part in any form or medium without express written permission of Ziff-Davis

Publishing Company is prohibited. The Cobb Group and The Cobb Group logo are trademarks of

Ziff-Davis Publishing Company.

Inside Solaris is a publication of The Cobb Group.
1-800-223-8720